package com.yc.thread;

public class Demo {
	
	public static void main(String[] args) throws InterruptedException {
		
		Thread thread = Thread.currentThread();
		System.out.println(thread.getId());
		System.out.println(thread.getName());
		
		Thread t1 = new Thread("张三") {
			public void run() {
				Thread thread = Thread.currentThread();
				System.out.println("t1: " + thread.getId());
				System.out.println("t1: " + thread.getName());
				for (int i = 0; i < 1000; i++) {
					System.out.println("t1: " + thread.getName());
				}
			};
		};
		t1.setPriority(1);
		t1.start();
		
		new Thread(()->{
			Thread t = Thread.currentThread();
			for (int i = 0; i < 1000; i++) {
				System.out.println("t2: " + t.getName());
			}
		},"李四").start();
		
		
		Thread t3 = new Thread(()->{
			Thread t = Thread.currentThread();
			for (int i = 0; i < 10; i++) {
				System.out.println("t2: " + t.getName());
				try {
					Thread.sleep(300);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}
			}
			System.out.println("t3 线程结束");
		},"王五");
		
		t3.setDaemon(true);
		t3.start();
		
		Thread.sleep(2000);
		
		System.out.println("main 线程结束");
		
		// 默认情况下， 父线程会在所有的子线程执行完成之后才结束
		// 反之， 主线程不会等待精灵线程
		
	}

}
